package com.AJava1710D.xiancheng;

import java.util.List;

/**
 * 作者: LCG
 * 日期: 2020/6/23 09:03
 * 描述: synchronized 代码块的使用 来完成同步操作
 */
public class RunableA implements Runnable {

    private List<Integer> list;

    public RunableA(List<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {

        for (int i=0;i<5000;i++){
            try {
                System.out.println("======add  A ========");
                synchronized (RunableA.class){
                    list.add(i);
                }
                Thread.sleep(0);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }


}
